<?php

error_reporting(E_ALL);

/**
 * untitledModel - class.ControladorUsr.php
 *
 * $Id$
 *
 * This file is part of untitledModel.
 *
 * Automatically generated on 27.11.2011, 19:02:44 with ArgoUML PHP module 
 * (last revised $Date: 2010-01-12 20:14:42 +0100 (Tue, 12 Jan 2010) $)
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/**
 * include ModeloUsr
 *
 * @author firstname and lastname of author, <author@example.org>
 */
require_once('class.ModeloUsr.php');

/**
 * include Usuarios
 *
 * @author firstname and lastname of author, <author@example.org>
 */
require_once('class.Usuarios.php');

/**
 * include VistaUsr
 *
 * @author firstname and lastname of author, <author@example.org>
 */
require_once('class.VistaUsr.php');

/* user defined includes */
// section 10-0-101-116-75074dcc:133e14e2698:-8000:0000000000001789-includes begin
// section 10-0-101-116-75074dcc:133e14e2698:-8000:0000000000001789-includes end

/* user defined constants */
// section 10-0-101-116-75074dcc:133e14e2698:-8000:0000000000001789-constants begin
// section 10-0-101-116-75074dcc:133e14e2698:-8000:0000000000001789-constants end

/**
 * Short description of class ControladorUsr
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class ControladorUsr
{
    // --- ASSOCIATIONS ---


    // --- ATTRIBUTES ---

    /**
     * Short description of attribute modelo
     *
     * @access public
     * @var Modelousr
     */
    public $modelo = null;

    /**
     * Short description of attribute vista
     *
     * @access public
     * @var VistaUsr
     */
    public $vista = null;

    /**
     * Short description of attribute usuario
     *
     * @access public
     * @var Usuario
     */
    public $usuario = null;

    /**
     * Short description of attribute mensaje
     *
     * @access public
     * @var String
     */
    public $mensaje = null;

    // --- OPERATIONS ---

    /**
     * Short description of method Lista
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Lista()
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A0 begin
		$cadena=$this->modelo->getAllRows();
		
		$this->vista->Lista("header.php",$cadena);
		$this->vista->Lista("VistaListaUser.php",$cadena);
		$this->vista->Lista("footer.php",$cadena);
		exit();
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A0 end
    }

    /**
     * Short description of method Alta
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Alta($datos)
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A2 begin
		
		if(@$datos['registrousr']!=null)
		{
			$this->modelo->InserRow($datos);
			$this->mensaje="Usuario registrado con Exito";
		}
		$this->vista->Alta("header.php");
		$this->vista->Alta("VistaAltaUser.php");
		$this->vista->Alta("footer.php");
		exit();
		
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A2 end
    }
	public function Reporte()
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A2 begin
		
		$cadena=$this->modelo->Maestros();
		$this->vista->Editar("header.php",$cadena);
		$this->vista->Editar("VistaListaReporte.php",$cadena);
		$this->vista->Editar("footer.php",$cadena);
		exit();
		
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A2 end
    }


    /**
     * Short description of method Editar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Editar($datos)
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A4 begin
		$this->modelo->UpdateRow($datos);
		$cadena=$this->modelo->getAllRows();
		$this->vista->Editar("header.php",$cadena);
		$this->vista->Editar("VistaListaUser.php",$cadena);
		$this->vista->Editar("footer.php",$cadena);
		exit();
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A4 end
    }

    /**
     * Short description of method Borra
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function MostrarBorra($valorid,$val)
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A6 begin
		$cadena= $this->modelo->getById($valorid);
		
			if($val==1){
				$this->vista->Borra("header.php",$cadena);
				$this->vista->Borra("VistaBajaUser.php",$cadena);
				$this->vista->Borra("footer.php",$cadena);
			}elseif($val==2){
				$this->vista->Editar("header.php",$cadena);
				$this->vista->Editar("VistaEditarUser.php",$cadena);
				$this->vista->Editar("footer.php",$cadena);
			}
		exit();
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A6 end
    }

	public function Borra($valorid)
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A6 begin
		$this->modelo->DeleteRows($valorid);
		$cadena=$this->modelo->getAllRows();
		$this->vista->Lista("header.php",$cadena);
		$this->vista->Lista("VistaListaUser.php",$cadena);
		$this->vista->Lista("footer.php",$cadena);
		exit();
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A6 end
    }
    /**
     * Short description of method Buscar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Buscar($datos)
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A8 begin
		
		$cadena= $this->modelo->SearchByEmail($datos['correo']);
		
		if(!empty($cadena) && @$datos['contra']==@$cadena[0]['contra'])
		{
			$_SESSION["usuario"]['nombre']=@$cadena[0]['nombre'];
			$_SESSION["usuario"]['correo']=@$cadena[0]['correo'];
			$_SESSION["usuario"]['nivel']=@$cadena[0]['nivel'];
			$this->vista->Bienvenida("header.php");
			$this->vista->Bienvenida("bienvenida.php");
			$this->vista->Bienvenida("footer.php");
				exit();
			
		}else
		{
			
			$this->mensaje="Correo o Password incorrecta";
		}
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A8 end
    }
	
	 public function Login()
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A8 begin
		$this->vista->Login("header.php");
		$this->vista->Login("VistaLogin.php");
		$this->vista->Login("footer.php");
		exit();
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017A8 end
    }

    /**
     * Short description of method ControladorUsr
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function ControladorUsr()
    {
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017AA begin
		$this->modelo = new ModeloUsr();		
		$this->vista = new VistaUsr();	
		$this->usuario = new Usuarios();

     	if ($this->usuario->IsLogged()==true && @$_REQUEST['registrousr'] == null && @$_REQUEST['borrarusr'] == null && @$_REQUEST['listausr'] == null && @$_REQUEST['opcion'] == null && @$_REQUEST['salir'] == null && @$_REQUEST['editaruser'] == null && @$_REQUEST['reporte']==null) 
		{	
        	//header("Location: VistaAltaUser.php");
			$this->vista->Bienvenida("header.php");
			$this->vista->Bienvenida("bienvenida.php");
			$this->vista->Bienvenida("footer.php");
				exit();
				
		}else
		{
			if(@$_REQUEST['Entrar'] != null && @$_REQUEST['correo'] != "" && @$_REQUEST['contra'] != "")
			{
				$this->Buscar($_REQUEST);
			}
			else if(@$_REQUEST['salir'] != null)
			{
				$this->usuario->LogOut();
			}
			else if(@$_REQUEST['Registrar'] != null)
			{
				$this->Alta($_REQUEST);
			}
			else if(@$_REQUEST['registrousr'] != null)
			{
				$this->Alta($_REQUEST);
			}
			else if(@$_REQUEST['listausr'] != null )
			{
				if($_SESSION["usuario"]['nivel']==1){
					$this->Lista();
				}else{
					$this->vista->Bienvenida("header.php");
					$this->vista->Bienvenida("bienvenida.php");
					$this->vista->Bienvenida("footer.php");
					}
			}
			else if(@$_REQUEST['opcion'] == 'desplegar')
			{
				$this->MostrarBorra(@$_REQUEST['id'],@$_REQUEST['dato']);
			}
			else if(@$_REQUEST['borrarusr'])
			{
				$this->Borra(@$_REQUEST['id']);
			}
			else if(@$_REQUEST['editaruser'])
			{
				$this->Editar(@$_REQUEST);
			}
			else if(@$_REQUEST['reporte'])
			{
				$this->Reporte();
			}
			
			
			$this->Login();
		}
	
        // section 10-0-101-116-75074dcc:133e14e2698:-8000:00000000000017AA end
    }

} /* end of class ControladorUsr */

?>